<?php

class Application_Form_FrmProduct extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    }
    public function AddProductForm($data=null) {
    	$user_info = new Application_Model_DbTable_DbGetUserInfo();
    	$result = $user_info->getUserInfo();
    	
    	$db=new Application_Model_DbTable_DbGlobal();
    	$tr = Application_Form_FrmLanguages::getCurrentlanguage();
    	
    	$nameElement = new Zend_Form_Element_Text('txt_name');
    	$nameElement->setAttribs(array('class'=>'validate[required]','placeholder'=>'Enter Product Name'));
    	$this->addElement($nameElement);
    	
    	$codeElement = new Zend_Form_Element_Text('txt_code');
    	$codeElement->setAttribs(array(
    			'placeholder'=>'Enter Product Code',
    			'class'=>'validate[required]',
    			'Onblur'=>'CheckPCode()',
    			));
    	$this->addElement($codeElement);
    	
    	$rowsBranch= $db->getGlobalDb('SELECT CategoryId, Name FROM tb_category WHERE Name!="" AND IsActive=1 ORDER BY CategoryId DESC ');
    	$options = "";
    	if($result["level"]==1 OR $result["level"]==2){
    		$options = array(""=>"Select Category","-1"=>"Add New Category");
    	}
    	if($rowsBranch) {
    		foreach($rowsBranch as $readCategory) $options[$readCategory['CategoryId']]=$readCategory['Name'];
    	}
    	$categoryElement = new Zend_Form_Element_Select('category');
    	$categoryElement->setAttribs(array('class' => 'validate[required]',
    			"Onchange"=>"showPopupCategory()"
    			));
    	$categoryElement->setMultiOptions($options);
    	$this->addElement($categoryElement); 

    	$rowsBranch= $db->getGlobalDb('SELECT branch_id, Name FROM tb_branch WHERE Name!="" AND IsActive=1 ORDER BY Name DESC ');
    	$options = "";
    	if($result["level"]==1 OR $result["level"]==2){
    		$options = array(""=>"Select Branch","-1"=>"Add New Branch");
    	}
    	if($rowsBranch) {
    		foreach($rowsBranch as $readBranch) $options[$readBranch['branch_id']]=$readBranch['Name'];
    	}
    	$branchElement = new Zend_Form_Element_Select('branch_id');
    	$branchElement->setAttribs(array('class' => 'validate[required]',"Onchange"=>"showPopupBranch()"));
    	$branchElement->setMultiOptions($options);
    	$this->addElement($branchElement);
    	
    	
    	$typeElement = new Zend_Form_Element_Select('type');
    	$typeElement ->setAttribs(array('id'=>'single'));
    	$typeElement->setMultiOptions(array(1=>$tr->translate("STOCKABLE"), 2=>$tr->translate("NON_STOCKED")));
    	//$typeElement->setAttribs(array('onChange'=>'showDiv("div",this)',));
    	$this->addElement($typeElement);
    	
    	$itemImageElement = new Zend_Form_Element_File('photo');
    	$this->addElement($itemImageElement);
    	
    	$costingMethodElement = new Zend_Form_Element_Select('costingmethod');
    	$costingMethodElement->setMultiOptions(array(1=>$tr->translate("Manual"), 2=>$tr->translate("Moving Average"),3=>$tr->translate("Last Purchase")));
    	$this->addElement($costingMethodElement);
    	
    	$priceElement = new Zend_Form_Element_Text('price');
    	$priceElement->setAttribs(array('class'=>'validate[custom[number]','placeholder'=>'Enter Product Price'));
    	$this->addElement($priceElement);
    	
    	$remarkElement = new Zend_Form_Element_Textarea('remark');
    	$this->addElement($remarkElement);
    
    	$balancelement = new Zend_Form_Element_Text('txt_balance');
    	$this->addElement($balancelement);
    	 
    	$addressElement = new Zend_Form_Element_Textarea('txt_address');
    	$this->addElement($addressElement);
    	 
    	$contactElement = new Zend_Form_Element_Text('txt_contact_name');
    	$contactElement->setAttribs(array('class'=>'validate[required]',));
    	$this->addElement($contactElement);
    	
    	if(!$data==null)
    	{
    		$idElement = new Zend_Form_Element_Hidden('id');
    		$this->addElement($idElement);
    		$idElement->setValue($data['pro_id']);
    		$itemImageElement->setValue($data['photo']);
    		$codeElement->setValue($data['p_code']);
    		$categoryElement->setValue($data['cate_id']);
    		$branchElement->setValue($data['branch_id']);
    		$nameElement->setValue($data['item_name']);
    		$typeElement->setValue($data['type']);
    		$priceElement->setValue($data['price']);    		
    		$remarkElement->setValue($data['remark']);
    	}	 
    	return $this;
    }
}
?>